\section{write --- file output}
\label{fn:write}
\index{write()}
\index{file!output}
\begin{rail}
Write : 'write' '(' String ',' ( ( Scalar | Matrix | String | List ) + ',' ) ')' ;
\end{rail}


\verb+write+ is a function that allows you to save variables to a
file.  The first argument specifies the file that you want to save
the variable(s) to.  Successive argument(s) specify the
variables to save.  If the file exists, it is cleared before
anything is written to it. The file is left open so you can write more
stuff out to it with more calls to \verb+write+.

\paragraph{Example}
\index{example of write()}
\index{write()!example}
\begin{verbatim}
> matrix_name = rand(2,2)
 matrix_name =
        1      0.647  
    0.975      0.333  
> scal452 = 2.3456123
 scal452 =
     2.35
> scalC = pi + exp(1)*1j
 scalC =
     3.14 + 2.72i
> another_matrix = rand(3,1) + rand(3,1)*1j
 another_matrix =
        0.0369 + 0.0847i
          0.162 + 0.204i
          0.665 + 0.167i
> str = "some test text"
 str =
some test text
> DerList = << str; scalC; another_matrix >>
 DerList =
   1            2            3         
> write("for_later", matrix_name);
> system("more for_later");
# matrix : matrix_name no_of_rows: 2 no_of_cols: 2 REAL
# matrix columns 1 thru 2
 0.9999996442347765       0.6474838890135288      
 0.9745195945724845       0.3330855811946094      
> write("_nother_file", scal452, matrix_name);
> system("more _nother_file");
# scalar : scal452
 2.3456123                0                       
# matrix : matrix_name no_of_rows: 2 no_of_cols: 2 REAL
# matrix columns 1 thru 2
 0.9999996442347765       0.6474838890135288      
 0.9745195945724845       0.3330855811946094      
> write("for_later", scalC, str, DerList, another_matrix);
> system("more for_later");
# matrix : matrix_name no_of_rows: 2 no_of_cols: 2 REAL
# matrix columns 1 thru 2
 0.9999996442347765       0.6474838890135288      
 0.9745195945724845       0.3330855811946094      
# scalar : scalC
 3.141592653589793        2.718281828459045       
# string : str Length : 14
some test text
# list : DerList no_of_elements: 3 
# string : 1 Length : 14
some test text
# scalar : 2
 3.141592653589793        2.718281828459045       
# matrix : 3 no_of_rows: 3 no_of_cols: 1 COMPLEX
# matrix columns 1 thru 1
 0.03694454254582524      0.08467286918312311     
 0.1617118660360575       0.2041363911703229      
 0.6646450059488416       0.1673069256357849      
# matrix : another_matrix no_of_rows: 3 no_of_cols: 1 COMPLEX
# matrix columns 1 thru 1
 0.03694454254582524      0.08467286918312311     
 0.1617118660360575       0.2041363911703229      
 0.6646450059488416       0.1673069256357849 
> close("_nother_file");
> close("for_later");
> write("for_later", another_matrix);
> system("more for_later");
# matrix : another_matrix no_of_rows: 3 no_of_cols: 1 COMPLEX
# matrix columns 1 thru 1
 0.03694454254582524      0.08467286918312311     
 0.1617118660360575       0.2041363911703229      
 0.6646450059488416       0.1673069256357849  
\end{verbatim}

See also: Page~\pageref{fn:close} \verb+close()+,
Page~\pageref{fn:read} \verb+read()+,
Page~\pageref{fn:readm} \verb+readm()+,
Page~\pageref{fn:writem} \verb+writem()+.

\newpage


